<template>
  <div class="add-card">
    <header class="add-header">
      <el-page-header content="查看月卡" @back="$router.back()" />
    </header>
    <main class="add-main">
      <div class="form-container">
        <div class="title">车辆信息</div>
        <div class="form">
          <div class="form-item">
            <span style="color:#ccc">车主姓名:</span>
            <span>{{ formData.personName }}</span>
          </div>
          <div class="form-item">
            <span style="color:#ccc">车票号码:</span>
            <span>{{ formData.carNumber }}</span>
          </div>
          <div class="form-item">
            <span style="color:#ccc">联系方式:</span>
            <span>{{ formData.phoneNumber }}</span>
          </div>
          <div class="form-item">
            <span style="color:#ccc">车辆品牌:</span>
            <span>{{ formData.carBrand }}</span>
          </div>
        </div>
      </div>
      <!-- 表格数据 -->
      <div class="form-container">
        <div class="title">月卡缴费信息</div>
        <div class="form">
          <el-table
            :data="tableData"
            style="width: 100%"
          >
            <el-table-column
              type="index"
              label="序号"
              width="180"
              align="center"
            />
            <el-table-column label="开始日期" prop="cardStartDate" />
            <el-table-column
              prop="cardEndDate"
              label="结束日期"
              align="center"
            />
            <el-table-column
              prop="paymentAmount"
              label="支付金额"
              align="center"
            />
            <el-table-column
              prop="paymentMethod"
              :formatter="dateFormat"
              label="支付方式"
              align="center"
            />
            <el-table-column
              prop="createTime"
              align="center"
              label="办理时间"
            />
            <el-table-column
              prop="createUser"
              align="center"
              label="办理人"
            />
          </el-table>
        </div>
      </div>

    </main>

  </div>
</template>

<script>
import { getCardAPI } from '@/api/addCard'
export default {
  data() {
    return {
      // 表单数据
      tableData: [],
      // 渲染数据
      formData: {
        carBrand: '',
        carNumber: '',
        carInfoId: '',
        personName: '',
        phoneNumber: ''
      }
    }
  },
  // 通过计算属性把路由传过来的ID存着
  computed: {

    id() {
      return this.$route.query.id
    }
  },
  mounted() {
    this.getCard()
  },
  methods: {
  // 渲染查看月卡
    async getCard() {
      const res = await getCardAPI(this.id)
      this.tableData = res.data.rechargeList
      this.formData = res.data
      console.log(res)
    },
    // 格式化表格
    dateFormat(row) {
      const MAP = {
        WeChat: '微信',
        Alipay: '支付宝',
        Cash: '现金'
      }
      return MAP[row.paymentMethod]
    }
  }
}
</script>

<style scoped lang="scss">
.table{
  width: 100%;
  border: none;
  text-align: center;

}
.add-card {
  background-color: #f4f6f8;
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;

    .left {
      span {
        margin-right: 4px;
      }
      .arrow{
        cursor: pointer;
      }
    }

    .right {
      text-align: right;
    }
  }

  .add-main {
    background: #f4f6f8;
    padding: 20px 130px;

    .form-container {
      background-color: #fff;

      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
      }

      .form {
        display: flex;
        justify-content: space-between;
         padding: 20px 65px 24px;
        flex: 1 ;
 flex-wrap: wrap;
        .form-item{

           span{

            color: #5e5a5a;
           }
        }
      }
    }
    .preview{
      img{
        width: 100px;
      }
    }
  }

  .add-footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 24px 50px;
    color: #000000d9;
    font-size: 14px;
    background: #fff;
    text-align: center;
  }
}
</style>
